package Servlet.QueryCourseServlet;

import Entity.Course;
import Service.QueryCourseService.QueryCourseService;
import Util.LayerResult;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.plaf.LayerUI;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
负责学生 查询所有审核通过可选课程信息 数据接口
 */
@WebServlet(value = "/queryStudentOnlineCourse")
public class QueryStudentOnlineCourse extends HttpServlet {
    private QueryCourseService queryCourseService = new QueryCourseService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("application/json; charset=utf-8");

        String studentId = request.getParameter("studentId");

        List<Course> list = queryCourseService.queryOnlineCourseByStudent(studentId);


        // 通过该类解析成 Layer 表格能识别的Json数据
        JSON json = LayerResult.getJson(list);

        PrintWriter out = response.getWriter();
        out.print(json);

    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
